import mysql.Mysql;



/**
 * Class Tiles
 */
public class Tile {

  //
  // Fields
  //

	
  private int id;
	private Component component;
//  private String image;
  
  //
  // Constructors
  //
  public Tile (Component c, String src) { 
	  this.component = c;
	  
  };
  
  //
  // Methods
  //


  /**
   * Set the value of component
   * @param newVar the new value of component
 * @return 
   */
  public boolean setComponent ( Component c ) {
	if (c == null) {
		this.component = null;
		return true;
	}
	  
    if (this.getComponent() == null) {
    	this.component = c;    	    	
    	return true;
    }
    
    return false;
  }

  /**
   * Get the value of component
   * @return the value of component
   */
  public Component getComponent ( ) {
    return component;
  }
  
  public boolean isEmpty() {
	  return this.component == null;	  
  }
  
  public void setId(int id) { 
	  this.id = id;
  }
  
  public int getId() {
	  return this.id;
  }
  
  public void save(int map_id, int x, int y) {
	  Mysql bd = new Mysql();
		String strsql;
		
		strsql = "insert into tb_tiles (map_id,x,y,component_id) value (" + 
		map_id + "," + x + "," + y + "," + this.component.getId() +")";
		
		bd.insertUpdate(strsql);
  }



}
